<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * C_Basic_Series_Edit
 * 基础套系编辑类
 * 杨继康
 */

class C_Basic_Series_Edit extends MY_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('Product_Model');
        $this->load->model('Series_Model');
        $this->load->model('series_product_Model');
        $this->load->model('System_Model');
    }

    /*
     * index
     * 初始化
     */

    public function index($id = FALSE) {
        $data['title'] = $this->System_Model->get_system('login_title');
        //如果为编辑，则获取该内容的详细信息
        $data['entity'] = $this->Series_Model->GetEntity($id);

        //获取产品信息
        $data['productlist'] = $this->Product_Model->GetListForState(OBJ_STATE_VALID);
        $this->load->view('layout/header', $data);
        $this->load->view('layout/menu');
        $this->load->view('basic/basic_series_edit_view', $data);
        $this->load->view('layout/footer');
    }

    /*
     * edit_Product
     * 编辑数据库信息
     */

    function edit_Product() {
        $se_id = $this->input->post('se_id');
        $data = array(
            'se_id' => $se_id,
            'se_name' => $this->input->post('se_name'),
            'se_moeny' => $this->input->post('se_moeny'),
            'se_state' => OBJ_STATE_VALID
        );
        $se_item = substr($this->input->post('se_item'), 0, -1);
        
        if ($se_id != NULL || $se_id != "") {
            //更新
            $array = split(";", $se_item);
            $this->Series_Model->Update_Product_Series($se_id, $data, $array);
        } else {
            //创建
            $array = split(";", $se_item);
            $this->Series_Model->Insert_Product_Series($data, $array);
        }
        //跳转
        redirect('basic/C_Basic_Series_List');
    }

    //异步获取数据列表
    function ajax_GetProduct($id = FALSE) {
        if ($id) {
            $listobj = $this->series_product_Model->GetListForState(OBJ_STATE_VALID, $id);
            echo json_encode($listobj);
        }
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */